$(function(){
	var $write = $('#write'),
		shift = false,
		capslock = false;
	
	$('#keyboard li').click(function(){
		var $this = $(this),
			character = $this.html(); // If it's a lowercase letter, nothing happens to this variable

		// Shift keys
		if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
			$('.symbol span').toggle();			
			shift = (shift === true) ? false : true;
			capslock = false;
			return false;
		}
		
		// Caps lock
		if ($this.hasClass('capslock')) {
			$('.symbol span').toggle();
			capslock = true;
			return false;
		}
		
		var id_char = $this.children("span:visible").attr('id');
		//alert(id_char);
		
			
		// Delete
		if ($this.hasClass('delete')) {
			var html = $write.html();
			id_char = -1;
//			$write.html(html.substr(0, html.length - 1));
//			return false;
		}
		
		// Special characters
		if ($this.hasClass('none')) id_char = $this.attr('id');
		
		//alert(id_char);
		
		// Remove shift once a key is clicked.
		if (shift === true) {
			$('.symbol span').toggle();
			//if (capslock === false) $('.letter').toggleClass('uppercase');
			shift = false;
		}
		
		// Add the character
		$write.html($write.html() + character);
		
		$.ajax({
			url: 'PasswordBlock.php',
			data: {key_id: id_char},
			success: function(data) {
				var timestamp = new Date().getTime();
				$("#txtPassword").attr('src','password.php?rnd='+timestamp);
				//alert(data);
		  }
		});
	});
});